﻿#region GNU General Public License
// XEdit2D - XNA 2D Asset Editor
// Copyright (C) 2010  HurlBat Games

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
#endregion

using System;
using System.Windows.Forms;
using System.Data;

namespace HurlBat.XEdit2D
{
    public partial class OptionsDialog : Form
    {
        public OptionsDialog()
        {
            InitializeComponent();
        }

        private void OptionsDialog_VisibleChanged(object sender, EventArgs e)
        {
            if (Visible)
            {
                txtContentFolder.Text = Globals.AppStore.ContentFolder;
                foreach (string item in Globals.AppStore.CharacterActions)
                    chkListActions.Items.Add(item);
            }
            else
            {
                Globals.AppStore.ContentFolder = txtContentFolder.Text;
                Globals.AppStore.CharacterActions = new string[chkListActions.Items.Count];
                for (int i = 0; i < chkListActions.Items.Count; i++)
                    Globals.AppStore.CharacterActions[i] = chkListActions.Items[i].ToString();
                Globals.AppStore.Save();
            }
        }

        private void btnSaveOptions_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Hide();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dlg = new FolderBrowserDialog();
            if (dlg.ShowDialog() != DialogResult.OK) return;
            txtContentFolder.Text = dlg.SelectedPath;
        }

        private void btnActionDelete_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show(string.Format("Are you sure you want to remove {0} items?",
                chkListActions.CheckedItems.Count), "Confirm",
                MessageBoxButtons.OKCancel, MessageBoxIcon.Question,
                MessageBoxDefaultButton.Button2) != DialogResult.OK) return;
            string[] items = new string[chkListActions.CheckedItems.Count];
            for (int i = 0; i < chkListActions.CheckedItems.Count; i++)
                items[i] = chkListActions.CheckedItems[i].ToString();
            foreach (string item in items)
                chkListActions.Items.Remove(item);
        }

        private void btnActionAdd_Click(object sender, EventArgs e)
        {
            string item = txtActionAdd.Text.Trim();
            if (chkListActions.FindStringExact(item) >= 0)
            {
                MessageBox.Show("This item already exists in the collection", "Add error");
                return;
            }
            chkListActions.Items.Add(item);
            txtActionAdd.Text = string.Empty;
        }
    }
}
